package com.cloud.drore.eboss.sso.dao;

import com.cloud.drore.eboss.sso.entity.ShiroUser;
import org.hibernate.annotations.SQLUpdate;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import java.util.List;

@Repository
public interface ShiroUserDao  extends BaseDao<ShiroUser, Long> {

  public ShiroUser findByUsernameAndPassword(String username, String password);

  public ShiroUser findByUsername(String username);

  public ShiroUser findFirstByEmail(String email);

  @Query(value = "from ShiroUser j where j.username = :username ")
  public ShiroUser findByUsernameForUpdate(@Param("username") String username);
  
  // 动态sql分页查询
  Page<ShiroUser> findAll(Specification<ShiroUser> spec, Pageable pageable);

  @Query(value ="update ShiroUser set password = :password")
  void updateUser(@Param("password") String password);

  @Query(value = "select j from ShiroUser j where j.type = :type and j.typeId =:typeId and j.isAdmin <>1 order by id desc ")
  public List<ShiroUser> findByTypeId(@Param("type") String type, @Param("typeId") Long typeId);

  ShiroUser findFirstByTypeIdAndIsAdmin(Long typeid, int isAdmin);
} 